//
//  mainGameViewController.m
//  mtrGameProject
//
//  Created by darkcl on 11-2-20.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "mainGameViewController.h"
#import "shinyUIView.h"
#import "nstimer.h"
#import "shopView.h"
#import "shopButton.h"

#define BUILD_BUTTON 1
#define UP_BUTTON 1
#define HIRE_BUTTON 2
#define DOWN_BUTTON 2
#define EQ_BUTTON 3
#define TARGET_BUTTON 4

#define FLOOR_WIDTH 480
#define FLOOR_HEIGHT 245

#define SHOP_WIDTH 47

@implementation mainGameViewController


// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

-(void) createContentView:(int) floorNumber{
	CGPoint tempPoint = CGPointMake(0, 254);
	UIImage *floorImage = [UIImage imageNamed:@"floor_background.png"];
	for (int i=0; i<floorNumber; i++) {
		UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(tempPoint.x, tempPoint.y, FLOOR_WIDTH, FLOOR_HEIGHT)];
		imageView.image = floorImage;
		imageView.tag = i;
		imageView.userInteractionEnabled = YES;
		UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, imageView.frame.size.width, 40)];
		titleLabel.text = [NSString stringWithFormat:@"%i",i];
		titleLabel.center = CGPointMake(imageView.frame.size.width/2, imageView.frame.size.height/2);
		titleLabel.font = [UIFont systemFontOfSize:30];
		titleLabel.textColor = [UIColor blackColor];
		titleLabel.textAlignment = UITextAlignmentCenter;
		titleLabel.backgroundColor = [UIColor clearColor];
		[imageView addSubview:titleLabel];
		[contentView addSubview:imageView];
		tempPoint.y += FLOOR_HEIGHT;
	}
	UIImage *lowestImage = [UIImage imageNamed:@"lowest_background.png"];
	NSLog(@"%@", NSStringFromCGPoint(tempPoint));
	UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(tempPoint.x, tempPoint.y, FLOOR_WIDTH, 251)];
	imageView.image = lowestImage;
	[contentView addSubview:imageView];
	[mtrView setFrame:CGRectMake(480, imageView.frame.origin.y + 14 , 1092, 149)];
	[contentView insertSubview:mtrView belowSubview:imageView];
	UISwipeGestureRecognizer *leftRecognizer;
	leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(hideMTR)];
	leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
	[mtrView addGestureRecognizer:leftRecognizer];
	mtrRect = mtrView.frame;
}

-(void) showMTR{
	if (mtrView.frame.origin.x == 480) {
		CGRect tempRect = mtrRect;
		tempRect.origin.x = 480-150;
		[UIView animateWithDuration:0.25 
							  delay:0.0 
							options:UIViewAnimationOptionAllowUserInteraction
						 animations:^{
							 [mtrView setFrame:tempRect];
						 } 
						 completion:^(BOOL finished){
							 [mtrTimer pause];
						 }];
	}
}

-(void) hideMTR{
	CGRect tempRect = mtrView.frame;
	tempRect.origin.x = -(mtrView.frame.size.width);
	[UIView animateWithDuration:0.25 
						  delay:0.0 
						options:UIViewAnimationOptionAllowUserInteraction
					 animations:^{
						 [mtrView setFrame:tempRect];
					 } 
					 completion:^(BOOL finished){
						 [mtrView setFrame:mtrRect];
						 [mtrTimer resume];
					 }];
}


-(void) updownControl:(int) control{
	switch (control) {
		case UP_BUTTON:
			if (currentFloor < totalFloor) {
				currentFloor ++;
				NSLog(@"%i",currentFloor);
				if (currentFloor == totalFloor) {
					startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +254 -2);
				}else {
					startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +254);
				}
				[gameScrollView setContentOffset:startingPoint animated:YES];
			}
			break;
		case DOWN_BUTTON:
			if (currentFloor > 0) {
				currentFloor --;
				NSLog(@"%i",currentFloor);
				if (currentFloor == totalFloor) {
					startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +254 -2);
				}else {
					startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +254);
				}
				[gameScrollView setContentOffset:startingPoint animated:YES];
				
			}else if (currentFloor == 0) {
				[gameScrollView setContentOffset:CGPointMake(0, 140) animated:YES];
			}
			break;
		default:
			break;
	}

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	shopArray = [[NSMutableArray alloc] initWithCapacity:10];
	totalFloor = 5;
	[self createContentView:totalFloor];
	
	gameScrollView.contentSize = CGSizeMake(480, 116+(FLOOR_HEIGHT*totalFloor)+188);
	
	//contentView.transform = CGAffineTransformScale(contentView.transform, 0.5, 0.5);
	[gameScrollView addSubview:contentView];
	gameScrollView.maximumZoomScale = 1.0;
	gameScrollView.minimumZoomScale = 0.5;
	
	gameScrollView.clipsToBounds = NO;
	gameScrollView.delegate = self;
	[gameScrollView setContentOffset:CGPointMake(0, 140)];
	timeFlow = 12;
//	//[self timeRotation];
	timeIconTimer = [NSTimer scheduledTimerWithTimeInterval:timeFlow target:self selector:@selector(timeRotation) userInfo:nil repeats:YES];
	[timeIconTimer fire];
	timerBackground = [NSTimer scheduledTimerWithTimeInterval:timeFlow/3 target:self selector:@selector(changeTimeBackground) userInfo:nil repeats:YES];
	[timerBackground performSelector:@selector(fire) withObject:nil afterDelay:timeFlow/3];
	[toolButton addTarget:self action:@selector(showToolBar) forControlEvents:UIControlEventTouchUpInside];
	//[toolButton setFrame:CGRectMake(20, 243, 40, 40)];
	//[self.view addSubview:toolButton];
	//[self.view addSubview:toolsView];
	[self.view bringSubviewToFront:toolsView];
	 //for (UIButton *theButton in toolsView.subviews) {
//		if (theButton.tag != 0) {
//			[theButton addTarget:self action:@selector(buttonControl:) forControlEvents:UIControlEventTouchUpInside];
//		}else {
//			[theButton addTarget:self action:@selector(zoomButton) forControlEvents:UIControlEventTouchUpInside];
//		}
//
//	}
	currentFloor = 0;
	currentDate = 0;
	startingPoint = CGPointMake(0, 254);
	UIGestureRecognizer *recognizer;
	UISwipeGestureRecognizer *leftRecognizer;
	leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showToolBar)];
	leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
	[toolsView addGestureRecognizer:leftRecognizer];
	recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(dismissToolBar)];
	[toolsView addGestureRecognizer:recognizer];
	
	UISwipeGestureRecognizer *upRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(scrollUP)];
	upRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
	[gameScrollView addGestureRecognizer:upRecognizer];
	
	UISwipeGestureRecognizer *downRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(scrollDown)];
	downRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
	[gameScrollView addGestureRecognizer:downRecognizer];
	
	[upRecognizer release];
	[downRecognizer release];
	[recognizer release];
	mtrTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(showMTR) userInfo:nil repeats:YES];
	//[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(zoomButton) userInfo:nil repeats:NO];
}

-(void) scrollUP{
	NSLog(@"Up");
	[self updownControl:UP_BUTTON];
}

-(void) scrollDown{
	NSLog(@"Down");
	[self updownControl:DOWN_BUTTON];
}

-(void) changeTimeBackground{
	switch (currentDate) {
		case 0:
			[UIView animateWithDuration:0.25 
								  delay:0.0 
								options:UIViewAnimationOptionAllowUserInteraction 
							 animations:^{
								 timeBackground.alpha = 0.0;
							 } 
							 completion:^(BOOL finished){
								 timeBackground.image = nil;
								 timeBackground.image = [UIImage imageNamed:@"sunset.png"];
								 [UIView animateWithDuration:0.25 
													   delay:0.0 
													 options:UIViewAnimationOptionAllowUserInteraction 
												  animations:^{
													  timeBackground.alpha = 1.0;
												  } 
												  completion:^(BOOL finished){
													  
												  }];
							 }];
			currentDate ++;
			break;
		case 1:
			[UIView animateWithDuration:0.25 
								  delay:0.0 
								options:UIViewAnimationOptionAllowUserInteraction 
							 animations:^{
								 timeBackground.alpha = 0.0;
							 } 
							 completion:^(BOOL finished){
								 timeBackground.image = nil;
								 timeBackground.image = [UIImage imageNamed:@"night.png"];
								 [UIView animateWithDuration:0.25 
													   delay:0.0 
													 options:UIViewAnimationOptionAllowUserInteraction 
												  animations:^{
													  timeBackground.alpha = 1.0;
												  } 
												  completion:^(BOOL finished){
													  
												  }];
							 }];
			currentDate ++;
			break;
		case 2:
			[UIView animateWithDuration:0.25 
								  delay:0.0 
								options:UIViewAnimationOptionAllowUserInteraction 
							 animations:^{
								 timeBackground.alpha = 0.0;
							 } 
							 completion:^(BOOL finished){
								 timeBackground.image = nil;
								 timeBackground.image = [UIImage imageNamed:@"morning.png"];
								 [UIView animateWithDuration:0.25 
													   delay:0.0 
													 options:UIViewAnimationOptionAllowUserInteraction 
												  animations:^{
													  timeBackground.alpha = 1.0;
												  } 
												  completion:^(BOOL finished){
													  
												  }];
							 }];
			currentDate = 0;
			break;
		default:
			break;
	}
}

-(void) timeRotation{
	[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:timeFlow];
    CABasicAnimation *rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
	rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0];
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
    rotationAnimation.duration = timeFlow;
    rotationAnimation.cumulative = NO;
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    [timeView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    [UIView commitAnimations];
}

-(void)pauseLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
    layer.speed = 0.0;
    layer.timeOffset = pausedTime;
	NSLog(@"Pause");
}

-(void)resumeLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer timeOffset];
    layer.speed = 1.0;
    layer.timeOffset = 0.0;
    layer.beginTime = 0.0;
    CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
    layer.beginTime = timeSincePause;
	NSLog(@"Resume");
}

-(void) zoomButton{
	
	//[gameScrollView zoomToRect:smallLabel.frame animated:YES];
	if (gameScrollView.zoomScale == 1.0) {
		[gameScrollView setZoomScale:0.5 animated:YES];
	}else {
		[gameScrollView setZoomScale:1.0 animated:YES];
	}
}

-(void) showToolBar{
	if (toolsView.frame.origin.x == 0) {
		return;
	}
	CGRect theRect = toolsView.frame;
	theRect.origin.x = 0;
	[UIView animateWithDuration:0.25
						delay:0.0 
						options:UIViewAnimationOptionAllowUserInteraction 
					animations:^{
						toolsView.frame = theRect;
						[self showStatusView];
						//statusView.alpha = 0.0;
					}
					completion:^(BOOL finished){
						[toolButton removeTarget:self action:@selector(showToolBar) forControlEvents:UIControlEventTouchUpInside];
						[toolButton addTarget:self action:@selector(dismissToolBar) forControlEvents:UIControlEventTouchUpInside];
						[toolButton setImage:[UIImage imageNamed:@"exitToolBarButton.png"] forState:UIControlStateNormal];
						[self pauseLayer:timeView.layer];
						NSLog(@"Current Floor : %i",currentFloor);
						[timeIconTimer pause];
						[mtrTimer pause];
						[timerBackground pause];
					}];
}

-(IBAction) dismissToolBar{
	if (toolsView.frame.origin.x == 405) {
		return;
	}
	CGRect theRect = toolsView.frame;
	theRect.origin.x = 405;
	[UIView animateWithDuration:0.25
						  delay:0.0 
						options:UIViewAnimationOptionAllowUserInteraction 
					 animations:^{
						 toolsView.frame = theRect;
						 [self resetStatusView];
						 //statusView.alpha = 1.0;
					 }
					 completion:^(BOOL finished){
						 [toolButton removeTarget:self action:@selector(dismissToolBar) forControlEvents:UIControlEventTouchUpInside];
						 [toolButton addTarget:self action:@selector(showToolBar) forControlEvents:UIControlEventTouchUpInside];
						 [toolButton setImage:[UIImage imageNamed:@"toolBarButton.png"] forState:UIControlStateNormal];
						 [self resumeLayer:timeView.layer];
						 [timeIconTimer resume];
						 [mtrTimer resume];
						 [timerBackground resume];
					 }];
}

-(void) showStatusView{
	UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
	dimView.backgroundColor = [UIColor blackColor];
	dimView.alpha = 0.0;
	dimView.tag = 10000;
	[self.view insertSubview:dimView aboveSubview:gameScrollView];
	[UIView animateWithDuration:0.25
						  delay:0.0 
						options:UIViewAnimationOptionAllowUserInteraction 
					 animations:^{
						 [statusView setCenter:CGPointMake(54, 29)];
						 dimView.alpha = 0.5;
					 }
					 completion:^(BOOL finished){
						 
					 }];
}

-(void) resetStatusView{
	UIView *tempView;
	for (UIView *dimView in self.view.subviews) {
		if (dimView.tag == 10000) {
			tempView=dimView;
		}
	}
	[UIView animateWithDuration:0.25
						  delay:0.0 
						options:UIViewAnimationOptionAllowUserInteraction 
					 animations:^{
						 [statusView setCenter:CGPointMake(92, -34)];
						 tempView.alpha = 0.0;
					 }
					 completion:^(BOOL finished){
						 [tempView removeFromSuperview];
					 }];
}
-(void) buttonControl:(id) sender{
	UIButton *theButton = (UIButton *)sender;
	[self controlView:theButton.tag];
}

-(void) shopButtonAction:(id) sender{
	shopButton *theButton = (shopButton *)sender;
	NSLog(@"%@",theButton.shopName);
	for (UIImageView *theImage in toolDetailView.subviews) {
		for (UILabel *theLabel in theImage.subviews) {
			[UIView animateWithDuration:0.25 
							 animations:^{
								 theLabel.center = CGPointMake(-(theLabel.frame.size.width/2), theLabel.center.y);
							 } 
							 completion:^(BOOL finished){
								 [theLabel removeFromSuperview];
							 }];
		}
	}
	CGSize tempSize = CGSizeMake(470/(10/theButton.type), 120);
	for (int i=0; i<(10/theButton.type); i++) {
		UIButton *shopButtons = [UIButton buttonWithType:UIButtonTypeRoundedRect];
		[shopButtons setFrame:CGRectMake(5+(tempSize.width*i), 27, tempSize.width, tempSize.height)];
		[[toolDetailView.subviews lastObject] addSubview:shopButtons];
	}
}

-(IBAction) zoomToLabel{
	//[gameScrollView zoomToRect:CGRectMake(smallLabel.frame.origin.x - smallLabel.frame.size.width, smallLabel.frame.origin.y - smallLabel.frame.size.height, 3*smallLabel.frame.size.width, 3*smallLabel.frame.size.height) animated:YES];
	
}

-(void) controlView:(int) forView{
	toolDetailView = [[UIView alloc] initWithFrame:CGRectMake(20,20,440,260)];
	switch (forView) {
		case BUILD_BUTTON:
			//[toolDetailView createTitle:@"Build" inPoint:CGPointMake(toolDetailView.center.x, 20)];
			[toolDetailView setFrame:CGRectMake(0, 0, FLOOR_WIDTH, FLOOR_HEIGHT)];
			UIImageView *imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"floor_background.png"]];
			[imageView setFrame:CGRectMake(0, 0, toolDetailView.frame.size.width, toolDetailView.frame.size.height)];
			//imageView.backgroundColor = [UIColor whiteColor]; 
			UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 14, 450, 203)];
			theLabel.text = [NSString stringWithFormat:@"Floor : %i",currentFloor];
			theLabel.textAlignment = UITextAlignmentCenter;
			[imageView addSubview:theLabel];
			imageView.userInteractionEnabled = YES;
			[toolDetailView addSubview:imageView];
			
			break;
		case HIRE_BUTTON:
			[toolDetailView createTitle:@"Hire" inPoint:CGPointMake(toolDetailView.center.x, 20)];
			[toolDetailView applyDefaultStyle];
			[toolDetailView applyShinyBackgroundWithColor:[UIColor darkGrayColor]];
			break;
		case EQ_BUTTON:
			[toolDetailView createTitle:@"Equipment" inPoint:CGPointMake(toolDetailView.center.x, 20)];
			[toolDetailView applyDefaultStyle];
			[toolDetailView applyShinyBackgroundWithColor:[UIColor darkGrayColor]];
			break;
		case TARGET_BUTTON:
			[toolDetailView createTitle:@"Target" inPoint:CGPointMake(toolDetailView.center.x, 20)];
			[toolDetailView applyDefaultStyle];
			[toolDetailView applyShinyBackgroundWithColor:[UIColor darkGrayColor]];
			break;
		default:
			break;
	}
	
	UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
	backView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.25];
	[backView addSubview:toolDetailView];
	UIButton *aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
	
	if (forView == BUILD_BUTTON) {
		aButton.center = CGPointMake(30, 67);
		[aButton addTarget:self action:@selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
	}else {
		aButton.center = CGPointMake(20, 20);
		[aButton addTarget:self action:@selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
	}

	[backView addSubview:aButton];
	if (forView == BUILD_BUTTON) {
		UIScrollView *buttonScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 228, 440, 59)];
		//int offset = 10;
		CGPoint tempPoint = CGPointMake(10, 10);
		for(int i=0; i<2; i++){
			shopButton *shopButtons = [[shopButton alloc] init];
			
			[shopButtons addTarget:self action:@selector(shopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
			shopButtons.tag = i;
			shopButtons.shopName = [NSString stringWithFormat:@"A %i long shop",i+1];
			if (i==0) {
				shopButtons.money = 1000;
				shopButtons.epValue = 100;
				shopButtons.clientValue = 10;
				shopButtons.type = i+1;
			}else {
				shopButtons.money = 2000;
				shopButtons.epValue = 150;
				shopButtons.clientValue = 20;
				shopButtons.type = i+1;
			}

			[shopButtons setTitle:[NSString stringWithFormat:@"%i",shopButtons.tag] forState:UIControlStateNormal];
			CGRect theRect = shopButtons.frame;
			theRect.origin = tempPoint;
			theRect.size = CGSizeMake(59, 49);
			[shopButtons setFrame:theRect];
			
			//[shopButton applyShinyBackgroundWithColor:[UIColor grayColor]];
			[buttonScroll addSubview:shopButtons];
			tempPoint.x += 69;
		}
		[buttonScroll setContentSize:CGSizeMake(tempPoint.x+69, 59)];
		[backView addSubview:buttonScroll];
	}
	backView.alpha = 0.0;
	backView.tag = 100;
	[self.view addSubview:backView];
	[UIView animateWithDuration:0.5 
					 animations:^{
						 backView.alpha = 1.0;
	}];
}

-(void) closeView:(id) sender{
	UIView *theView = (UIView *) sender;
	[UIView animateWithDuration:0.5 
					 animations:^{
						 theView.superview.alpha = 0.0;
					 } 
					 completion:^(BOOL finished){
						 [toolDetailView removeFromSuperview];
						 [toolDetailView release];
						 toolDetailView = nil;
					 }];
	
}

#pragma mark -
#pragma mark Building View Related
-(void) createShopInPoint:(CGPoint) point{
	
}

#pragma mark -
#pragma mark Scroll View Delegate Method

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
	return contentView;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
	NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
	
}

//- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
//	if (scrollView == gameScrollView && currentFloor > 0) {
//		currentFloor = (int)scrollView.contentOffset.y / FLOOR_HEIGHT;
//		NSLog(@"%i",currentFloor);
//		startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +116);
//		if (currentFloor != totalFloor) {
//			[scrollView setContentOffset:startingPoint animated:YES];
//		}
//	}
//}
//
//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//	if (scrollView == gameScrollView) {
//		currentFloor = (int)scrollView.contentOffset.y / FLOOR_HEIGHT;
//		NSLog(@"%i",currentFloor);
//		startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +116);
//		if (currentFloor != totalFloor && currentFloor > 0) {
//			[scrollView setContentOffset:startingPoint animated:YES];
//		}
//	}
//	
//}
//- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
//	if (scrollView == gameScrollView) {
//		currentFloor = (int)scrollView.contentOffset.y / FLOOR_HEIGHT;
//		NSLog(@"%i",currentFloor);
//		startingPoint = CGPointMake(startingPoint.x, FLOOR_HEIGHT * currentFloor +116);
//		if (currentFloor != totalFloor && currentFloor > 0) {
//			[scrollView setContentOffset:startingPoint animated:YES];
//		}
//	}
//}

#pragma mark -
#pragma mark Touch Handling

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	UITouch *myTouch = [[event allTouches] anyObject];
	
	NSLog(@"%@",NSStringFromCGPoint([myTouch locationInView:self.view]));
	
}

#pragma mark -
#pragma mark Memory Management
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
